<?php
namespace app\index\controller;
use think\Db;

class Cate extends Base
{
	public function initialize(){
	    parent::initialize();
	}
    public function index()
    {	$id = request()->param('id');
		
		$this->assign('article',$this->getCateArticle($id));
		$this->assign('prev',$this->getPrevNext($id,'<'));
		$this->assign('next',$this->getPrevNext($id,'>'));
		return $this->fetch();
    }
	protected function getCateArticle($id){
		$page = request()->param('page');
		$limit = request()->param('limit');
		$where['status'] = 1;
		if(!empty($id)){
			$where['cate'] = $id;
		}
		$list = Db::name('article')->where($where)->paginate($limit)->each(function($item, $key){
			$item['url'] = url('article/index',['id'=>$item['id']]);
			$item['tag'] = $this->getTagList($item['tag']);
			return $item;
		});
		$res['data'] = $list->items();
		$res['page'] = $list->render();
		return $res;
	}
}
